<!doctype html>
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html>
<head>
<meta charset="utf-8">

<jsp:include page="/common/commonCss.jsp"/>
<jsp:include page="/common/commonJs.jsp"/>
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/global.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/layout.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/easyui.css">
<link rel="stylesheet" type="text/css" href="${basePath }commonCss/css/zTreeStyle.css">

<script src="${basePath }commonJs/jquery.min.js"></script>
<script src="${basePath }commonJs/jquery.easyui.min.js"></script>
<script src="${basePath }commonJs/jt_normal.js"></script>
<script src="${basePath }commonJs/jt_select.js"></script>
<script src="${basePath }commonJs/jquery.ztree.all.js"></script>
<script language="javascript" src="${basePath }commonJs/tags/My97DatePicker/WdatePicker.js"></script>


<script src="${basePath }commonJs/promotion/wolf_common.js"></script>
<script src="${basePath }commonJs/promotion/wolf_validation.js"></script>
<title>嘉童游乐中心-商品信息</title>
</head>

<SCRIPT type="text/javascript">
		 //标记被选中节点
		var setting = {
			check: {
				enable: true,
				chkboxType: { "Y": "ps", "N": "s" }
			},
			data: {
				simpleData: {
					enable: true
				}
			}
		};

		$(document).ready(function(){
			defualtZtree();
		});
		
		function defualtZtree(){
			$.ajax({ 
				url: "${basePath }authority/role/seacheByPidSecObj.shtml",
				data:"pid=",
				dataType: 'json',
				type:'POST',
				success: function(data){
					if(wolf.isNotNull(data)){
						$.fn.zTree.init($("#sptree"), setting, data);
					}
		      	}
			});
		}
		
		/**
			获取所有选中节点
		*/
		function getZtreeCheckNodes(){
			var checkNode = "";
			var treeObj = $.fn.zTree.getZTreeObj("sptree");
			var nodes = treeObj.getCheckedNodes(true);
			if(wolf.isNotNull(nodes)){
				wolf.data_foreach(nodes, function(i,node){
					var nodeObj = "&secObjList["+i+"].fkObjId="+node.id;
					var s = node.getCheckStatus();
					if(s.half == true && s.checked == true){
						nodeObj += "&secObjList["+i+"].chkStat="+1;
					}else{
						nodeObj += "&secObjList["+i+"].chkStat="+0;
					}
					checkNode += nodeObj;
				});
			}
			return checkNode;
		}
		
		function isNull(){
			var tit = "";
			var flag = false;
			if(wolf.isNull($("#roleName").val()) ){
				tit += "角色名称不能为空！\n";
				flag = true;
			}
			/* if(wolf.isNull($("#roleDesc").val())){
				tit += "角色描述不能为空！\n";
				flag = true;
			} */
			if(flag){
				alertInfo(tit);
			}
			return flag;
		}
		/**提交数据*/
		function form_submit(){
			if(!isNull()){
				var treeNode = getZtreeCheckNodes();
				$.ajax({ 
					url: "${basePath }authority/role/addRole.shtml",
					data:"roleName="+$("#roleName").val()+"&roleDesc="+$("#roleDesc").val()+treeNode,
					dataType: 'json',
					type:'POST',
					success: function(data){
						window.location.href="${basePath }authority/role/home.shtml";
			      	}
				});
			}
		}
		function isCheckRoleName(){
			var roleName = $("#roleName").val();
			if(wolf.isNotNull(roleName)){
				$.ajax({ 
					url: "${basePath }authority/role/seacheByRoleName.shtml",
					data:"roleName="+roleName,
					dataType: 'json',
					type:'POST',
					success: function(data){
						if(wolf.isNotNull(data)){
							$("#roleName").val("");
							alertInfo("该角色已经存在，请重新输入！");
						}
			      	}
				});
			}
			
		}
	</SCRIPT>
<title>嘉童游乐中心-库存调整</title>
</head>
<body class="bg">
<div class="content m_auto">
	<div class="content_l mt10">
    	<ul>
    		  	<shiro:hasPermission name="authority/role/home.shtml">
         <li   class="content_hover"><a href="${basePath}authority/role/home.shtml"><i class="nav_icon_u"></i><br>角色管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="authority/user/home.shtml">
            <li><a href="${basePath}authority/user/home.shtml"><i class="nav_icon_t"></i><br>用户管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="SalesRelation/mem.shtml">
            <li><a href="${basePath}SalesRelation/mem.shtml"><i class="nav_icon_s"></i><br>销售关联会员</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="ParRoomDetail/ParRoom.shtml">
            <li><a href="${basePath}ParRoomDetail/ParRoom.shtml"><i class="nav_icon_r"></i><br>房间管理</a></li>
           </shiro:hasPermission>
           <shiro:hasPermission name="SysBarCode/system.shtml">
            <li><a href="${basePath }SysBarCode/system.shtml"><i class="nav_icon_q"></i><br>条码维护</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="WfmAuthorize/toShenP.shtml">
            <li><a href="${basePath}WfmAuthorize/toShenP.shtml"><i class="nav_icon_s"></i><br>审批转授权</a></li>
            </shiro:hasPermission>
            <shiro:hasPermission name="holiday/sysHoliday.shtml">
            <li><a href="${basePath}holiday/sysHoliday.shtml"><i class="nav_icon_q"></i><br>节假日管理</a></li>
            </shiro:hasPermission>
        </ul>
    </div>
    <div class="content_r mt10">
    	<!---- 内容 --->
        <div class="file_single_dl_x fixed mt20">
        	<dl>
            	<dd><label>角色名称：</label><input type="text" class="iput_t w200" name="roleName" id="roleName" onblur="isCheckRoleName()">
            				<span class="color_red ml5">*</span></dd>
                <dd><label>角色描述：</label><input type="text" class="iput_t w200" name="roleDesc" id="roleDesc"></dd>
            </dl>
            <div class="clear"></div>
            <div><label>角色权限：</label>
            	<div class="ztree ztree_x fl" id="sptree"></div>
            </div>
        </div>
        <!----底部按钮----->
        <div class="btm_btn mt10">
                <dl>
                <dd><input type="button" class="btn" value="保存" onClick="form_submit()"></dd>
                    <dd><input type="button" class="btn" value="返回" onClick="javascript:window.location.href='${basePath }authority/role/home.shtml'"></dd>
                    
                </dl>
        </div>
        <!----底部按钮----->
        <!---- 内容 --->
    </div>
</div>


</body>
</html>